<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Report - MyOnlineShop.com</title>
        <link href="../script/myOnlineShop.css" rel="stylesheet" />
        <script type="text/javascript" src="../script/myReport.js"></script>
    </head>
    <body>
        <form name="rptForm">
            <input type="hidden" name="hidCurPage" id="hidCurPage" />
            <input type="hidden" name="hidTotalPage" id="hidTotalPage" />
            <input type="hidden" name="hidStartNum" id="hidStartNum" />
            <input type="hidden" name="hidEndNum" id="hidEndNum" />
            <input type="hidden" name="hidNCounter" id="hidNCounter" />
            <?php
            include("../utility/connection.php");
            include("../utility/general.php");
            include("../model/mBarang.php");
            @session_start();

            $resAllBarang = fnAllBrg();
            if ((isset($_SESSION['startNum'])) && (isset($_SESSION['endNum']))) {
                $startNum = $_SESSION['startNum'];
                $endNum = $_SESSION['endNum'];
                $resAllBarang = fnAllBrgByRange($startNum, $endNum);
            }

            $TotalBarang = fnAllBrg();
            $TotalRow = mysql_num_rows($TotalBarang);
            ?>
            <table border="1" cellpadding="2" cellspacing="2">
                <tr style="background-color: #376BAD; font-weight: bold; color: #FFFFFF">
                    <!-- header table -->    
                    <?php
                    if ($resAllBarang) {
                        $arrCount = mysql_num_fields($resAllBarang);
                        for ($colCounter = 0; $colCounter <= $arrCount - 2; $colCounter++) {
                            $field_info = mysql_fetch_field($resAllBarang, $colCounter);
                            ?>
                            <td><?php echo $field_info->name ?></td>
                            <?php
                        }
                    }
                    ?>
                </tr>
                <!-- body table -->    
                <?php
                $maxRowPerPage = 5;
                $maxRow = 1; // jumlah loop
                $nPage = 1; // initial halaman
                if (isset($_SESSION['curPage'])) {
                    $nPage = $_SESSION['curPage'];
                }
                $nTotPage = 1;
                $arrCount = 1; // initial column count
                if ($resAllBarang) {
                    // hitung jumlah loop
                    if ($TotalRow < $maxRowPerPage) {
                        $maxRow = $TotalRow;
                    } else {
                        $maxRow = $maxRowPerPage;
                    }
                    // hitung jumlah halaman
                    $nCekPage = $TotalRow % $maxRowPerPage;
                    if ($nCekPage == 0) {
                        $nTotPage = $TotalRow / $maxRowPerPage;
                    } else {
                        $nTotPage = (($TotalRow - $nCekPage) / $maxRowPerPage) + 1;
                    }
                    for ($rowCounter = 1; $rowCounter <= $maxRow; $rowCounter++) {
                        $rowAllBarang = mysql_fetch_array($resAllBarang);
                        ?>
                        <tr valign="top" style="background-color: #C8D7EB">
                            <?php
                            $arrCount = mysql_num_fields($resAllBarang);
                            for ($counter = 0; $counter <= $arrCount - 2; $counter++) {
                                ?>
                                <td align="left"><?php echo $rowAllBarang[$counter] ?></td>
                                <?php
                            }
                            ?>
                        </tr>
                        <?php
                        $nCounter = $rowAllBarang[0];
                        if ($nCounter == $TotalRow) {
                            break;
                        }
                    }
                    ?>
                    <tr>
                        <td colspan="<?php echo $arrCount - 1 ?>">
                            <button type="button" onclick="fnFirstCatalog()" name="btFirst" id="btFirst">First</button>
                            <button type="button" onclick="fnPrevCatalog()" name="btPrev" id="btPrev">Prev</button>

                            <input type="text" name="txtCurPage" id="txtCurPage" size="2" value="<?php echo $nPage ?>">
                            <input type="text" name="txtTotalPage" id="txtTotalPage" size="2" value="<?php echo $nTotPage ?>">
                            <input type="text" name="txtRecordPerPage" id="txtRecordPerPage" size="2" value="<?php echo $maxRow ?>">
                            <input type="text" name="txtTotalRow" id="txtTotalRow" size="2" value="<?php echo $TotalRow ?>">

                            <button type="button" onclick="fnNextCatalog()" name="btNext" id="btNext">Next</button>
                            <button type="button" onclick="fnLastCatalog()" name="btLast" id="btLast">Last</button>
                        </td>
                    </tr>
                    <?php
                }
                ?>
            </table>
        </form>
    </body>
</html>
